package com.study.zouchao.superproject.comtaskdetail.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.study.zouchao.superproject.R;
import com.study.zouchao.superproject.base_zou.ZouImgLoader;
import com.study.zouchao.superproject.comtaskdetail.model.TaskDetailResult;
import com.study.zouchao.superproject.travellist.adapter.TravelRecyclerViewAdapter;

import java.util.List;

/**
 * Created by Administrator on 2017/6/20.
 */

public class SupportListAdapter extends RecyclerView.Adapter<SupportListAdapter.MyViewHolder> {

    private List<TaskDetailResult.TaskDetailDataBean.EnrolledListBean> mDatas;
    private Context mContext;
    private TravelRecyclerViewAdapter.IRvItemClickListener mListener;

    public SupportListAdapter(Context context, List<TaskDetailResult.TaskDetailDataBean.EnrolledListBean> datas) {
        mContext = context;
        mDatas = datas;
    }

    public void setOnItemClickListener(TravelRecyclerViewAdapter.IRvItemClickListener listener) {
        mListener = listener;
    }

    @Override
    public SupportListAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_support_list, parent, false);
        return new SupportListAdapter.MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(SupportListAdapter.MyViewHolder holder, int position) {
        if (holder != null) {
            TaskDetailResult.TaskDetailDataBean.EnrolledListBean item = mDatas.get(position);
            ZouImgLoader.loadImage(mContext, holder.iv, item.getEnrollHeadimg(), R.drawable.error);
        }
    }

    //返回View中Item的个数，这个时候，总的个数应该是ListView中Item的个数加上HeaderView和FooterView
    @Override
    public int getItemCount() {
        return mDatas.size();
    }

    @Override
    public int getItemViewType(int position) {
        return 1;
    }

    /**
     * Holder
     */
    class MyViewHolder extends RecyclerView.ViewHolder {
        View mItemView;
        ImageView iv;

        public MyViewHolder(View itemView) {
            super(itemView);
            iv = (ImageView) itemView.findViewById(R.id.id_iv_support);
        }

    }

    public interface IRvItemClickListener {
        void onItemClick(View v, String title, String bgImg, String url);
    }
}
